<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>查找所有终端</title>
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/common.css" media="all">
    <link rel="stylesheet" href="../viewstyle/css/publicform.css">
    <script src="/js/layui/layui.js"></script>
    <!--<script src="/admin/js/token.js"></script>-->
</head>
<style type="text/css">
    .layui-form-label {
        padding: 9px 10px;
        width: 60px;
    }
</style>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <form class="layui-form layui-card-header layuiadmin-card-header-auto">

            <div class="layui-form-item">
                <div class="layui-inline">
                    <lable class="layui-form-label">房间号</lable>
                    <div class="layui-input-inline">
                        <input type="text" name="" id="room" value="" placeholder="" class="layui-input"/>
                    </div>
                </div>

                <div class="layui-inline">
                    <lable class="layui-form-label">MAC地址</lable>
                    <div class="layui-input-inline">
                        <input type="text" name="" id="mac" value="" placeholder="" class="layui-input"/>
                    </div>
                </div>

                <div class="layui-inline">
                    <button id="btnsearch" class="layui-btn layuiadmin-btn-admin">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>搜索
                    </button>
                </div>
            </div>
        </form>

        <div class="layui-card-body">
            <table class="layui-table" lay-filter="t" id="station"></table>
        </div>
    </div>
</div>
</body>
<script type="text/html" id="delAndEdit">
    <input type="button" value="设置密钥" class="layui-btn layui-btn-sm" lay-event="key"/>
</script>
<script>
    layui.use(['form', 'table'], function () {
        var form = layui.form;
        var $ = layui.$;
        var table = layui.table;
        var data = layui.data("terminal");
        var stationid = data.getdata.key_site
        var terminalkeyid = data.getdata.terminal_key_id;
        table.render({
            elem: "#station",
            url: "/admin/terminal-key/findByStationIdQueryTerminal?terminal_station=" + stationid,
            id: "t",
            toolbar: "#tol",
            cols: [[{
                title: "终端ID",
                field: "terminal_id",
                width: "15%",
                align: "center"
            }
                , {
                    title: "mac地址",
                    field: "terminal_mac",
                    width: "25%",
                    align: "center"
                }
                , {
                    title: "房间号",
                    field: "termina_room",
                    width: "20%",
                    align: "center"
                }
                , {
                    title: "密钥",
                    field: "termina_key",
                    width: "20%",
                    align: "center"
                }
                , {
                    title: "操作",
                    toolbar: "#delAndEdit",
                    width: "20%",
                    align: "center"
                }
            ]],
            page: true,
            limit:40
        });
        //搜索的监听时间
        $('#btnsearch').click(function () {
            table.reload('t', {
                where: {
                    terminal_room: $("#room").val(),
                    terminal_mac: $("#mac").val(),
                },
                page: {
                    curr: 1
                }
            })
        });

        //键盘回车监听
        $(window).keypress(function (event) {
            if (event.which === 13) {
                $('#btnsearch').click();
            }
        })

        //    右侧按钮的监听事件
        table.on('tool(t)', function (obj) {
            var getdata = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            switch (layEvent) {
                case "key":
                    var close = layer.confirm("您确定要给该终端设置密钥吗？", {
                        title: "提示？",
                        btn: ["标准型", "钟点型", "取消"],
                        btn1: function () {
                            $.ajax({
                                type: "post",
                                url: "/admin/terminal/TerminalByIdUpdateTermainal_keyByIdupdate",
                                data: {
                                    terminalId: getdata.terminal_id,
                                    terminalKeyId: terminalkeyid
                                },
                                success: function (res) {
                                    switch (res.code) {
                                        case 3:
                                            layer.msg(res.data, {
                                                icon: 2
                                            })
                                            break;
                                        case 2:
                                            layer.msg(res.data, {
                                                icon: 2
                                            })
                                            break;
                                        case 0:
                                            layer.msg(res.data, {
                                                icon: 1
                                            })
                                            layer.close(close);
                                            setTimeout(function () {
                                                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                                parent.layer.close(index);    //关闭弹出层
                                            }, 2000)
                                            break;
                                    }
                                }
                            })
                        },
                        btn2: function () {
                            layui.data("terminalid", {
                                key: "terminalid",
                                value: getdata.terminal_id
                            })
                            layer.open({
                                title: "设置钟点房时间",
                                content: "SetTime.html",
                                type: 2,
                                area: ["400px", "300px"],

                                end: function () {
                                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                    parent.layer.close(index);    //关闭弹出层
                                    $(".layui-laypage-btn").click();
                                }
                            });
                        }
                    })
                    break;
            }
        })
    })
</script>
</html>